package com.example.demo.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.po.Find;
import com.example.demo.service.FindService;

@RestController
@RequestMapping("/api/find")
public class FindApi {
	@Autowired
	private FindService FindService;
	
	@RequestMapping("/all")
	public List<Find> all() {
		return FindService.selectAll();
	}
	@RequestMapping("/one")
	public Find one(Integer id) {
		
		
	 return	FindService.selectById(id);
	}
	@RequestMapping("/one1/{id}")
	public Find one1(@PathVariable("id") Integer id) {
		return FindService.selectById(id);
	}
	@RequestMapping("/add")
	public String add(Find Find) {
		FindService.insert(Find);
		return "添加成功！";

	}
	@RequestMapping("/add1")
	public String add(@RequestBody JSONObject json) {
		Find Find=null;
		Find=JSON.toJavaObject(json, Find.class);
		System.out.println("添加成功");
		FindService.insert(Find);
		return "添加成功";
		
		

	}
	@RequestMapping("/update1")
	public String update(@RequestBody JSONObject json) {
		System.out.println(11111111);
		Find Find=null;
		
		Find=JSON.toJavaObject(json, Find.class);
		FindService.update(Find);
		return "修改成功";
	}
	@RequestMapping("/update")
	public String update(Find Find) {
		FindService.update(Find);
		return "修改成功";
	}
	@RequestMapping("/delete")
	public String delete(Integer id) {
		FindService.delete(id);
		return "删除成功！";
	}
	@RequestMapping("/delete1/{id}")
	public String delete1(@PathVariable("id") Integer id) {
		FindService.delete(id);
		return "删除成功";
	}
	

}
